Tool = {
    /*1.空值null/""校验，返回true
    !:将变量转为boolean类型，!(obj)=false
    数字注意：number=true !number=false !!number=true  (number是数字，返回true，!number不是数字，返回false)
    字符串注意：string=true !string=false !!string=true (同上)
    对象注意：{}=true !{}=false !!{}=true
    null=false !null=true !!null=false
    undefined=false !undefined=true !!undefined=false

     */
    isEmpty: function (obj) {
        if (typeof obj === 'string') {
            //如果为string，去空格，变为空. obj=string 返回false
            return !obj || !obj.replace(/\s+/g, "");
        } else {
            //转obj为字符串str
            return (!obj || JSON.stringify(obj) === "{}" || !obj.length === 0);
        }
    },
    //2.非空校验
    isNotEmpty: function (obj) {
        //非空，对于空取反，全部返回true
        return !this.isEmpty(obj);
    },
    //3.长度校验
    isLength: function (str, min, max) {
        return $.trim(str).length >= min && $.trim(str).length <= max;
    },

    //4.增加日期格式化方法
    dateFormat: function (format, date) {
        let result;
        if (!date) {
            date = new Date();
        }
        const option = {
            "y+": date.getFullYear().toString(),
            "M+": (date.getMonth() + 1).toString(), //月份需要加1
            "d+": date.getDate().toString(), //day为一周的第几天，date为一个月的第几天
            "h+": date.getHours().toString(),
            "m+": date.getMinutes().toString(),
            "s+": date.getSeconds().toString()
        };
        for (let i in option) {
            result = new RegExp("(" + i + ")").exec(format);
            if (result) {
                format = format.replace(result[1], (result[1].length == 1) ? (option[i]) : (option[i].padStart(result[1].length, "0")));
            }
        }
        return format;
    },
    //5.移除数组中的对象
    removeObj: function (array, obj) {
        let index = -1;
        for (let i = 0; i < array.length; i++) {
            if (array[i] === obj) {
                array.splice(i, 1);
                index = i;
                break;
            }
        }
        return index;
    },
    //6.md5转换10进制转62进制
    md_10to64: function (number) {
        let chars = '0123456789abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ';
        let radix = chars.length;//基数长度
        let arr = [];
        do {
            let mode = number % radix;
            number = (number - mode) / radix;
            arr.unshift(chars[mode]);
        } while (number);
        return arr.join('');
    },
    //7.保存员工登录
    setEmpLogin: function (empLogin) {
        SessionStorage.set(EMP_LOGIN, empLogin);
    },
    //8.获取登录信息，如果为null会报错，需要|| {} 空对象{}.empLogin不会报错
    getEmpLogin: function () {
        return SessionStorage.get(EMP_LOGIN) || {};
    },
    /**9.随机八位字符串生成imgCodeToken
     * 随机生成[length]长度的[radix]（基数）进制数,radix默认62(10个数字26个大写26个小写)
     * 随机生成0-61的数值，8位，重复循环8次，重复概率为62的8次方
     * 如果怕重复，可调整length
     */
    get8UUID: function (length, radix) {
        let char = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
        let uuid = [];
        radix = radix || char.length;
        for (let i = 0; i < length; i++) {
            uuid[i] = char[0 | Math.random() * radix];
        }
        return uuid.join('');
    },
    /**
     * 获取登录emp资源权限
     */
    authorityResources: function (uniId) {
        //获取employeeLoginDto中缓存的List<resourcesDto>资源数据
        let resources = this.getEmpLogin().resourcesDtos;
        if (this.isEmpty(resources)) {
            return false;
        }
        for (let i = 0; i < resources.length; i++) {
            if (uniId === resources[i].uniId) {
                return true;
            }
        }
        return false;
    },
    /*tree型数据过滤*/
    filterTree(data) {
        for (let i = 0; i < data.length; i++) {
            if (data[i].children.length < 1) {
                data[i].children = undefined;
            } else {
                this.filterTree(data[i].children);
            }
        }
        return data;
    },
    /*类型id转换value*/
    optionObjectKV(object, key) {
        console.log("传入得对象：", object,"传入的key：",key);
        //传入非list，非key,undefined=空,这里不能使用!key，非key会连同0一起判定，这里我们有type=0，使用key=null
        let KV = "";
        for (let enums in object) {
            console.log("enumsFilter传入的enums: ",enums,"-----objKey: ",object[enums].key);
            if(object[enums].key===key){
                KV=object[enums].value;
                console.log("KV入值：",KV);
            }
        }
        return KV;

    },
}